﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using ESOL.Business.Mst;
using ESOL.Business.Sales;
using ESOL.Business.Hr;
using ESOL.Common;
using ESOL.Common.Entity;
using ESOL.WinUI.MasterData;
using ESOL.WinUI.UICommon;
using DevExpress.XtraEditors.Controls;
using ESOL.WinUI.Hr;
using ESOL.WinUI.Sales;

namespace ESOL.WinUI.Finance
{
    public partial class frmMaintainExpensesClaims : BaseForm.frmBaseDialogyBusinessForm
    {
        #region Variable
        public SalesFeeEntity SelectedSalesFee { get; set; }
        public ApproveType ThisApproveType { get; set; }
        #endregion

        #region Constructor
        public frmMaintainExpensesClaims()
        {
            InitializeComponent();
            if (SelectedSalesFee == null)
            {
                SelectedSalesFee = new SalesFeeEntity();
                SelectedSalesFee.SalesFeeId = Guid.NewGuid().ToString();
            }
        }
        public frmMaintainExpensesClaims(MstCustomerEntity customer)
        {
            InitializeComponent();
            if (SelectedSalesFee == null)
            {
                SelectedSalesFee = new SalesFeeEntity();
                SelectedSalesFee.SalesFeeId = Guid.NewGuid().ToString();
            }
            txtCustomer.Tag = customer;
        }
        #endregion

        #region Functions
        private void SetFieldsByCustomer(MstCustomerEntity customer)
        {
            if (customer != null)
            {
                txtCustomer.Tag = customer;
                txtCustomer.Text = customer.CustomerFullName;
            }
            else
            {
                txtCustomer.Tag = null;
                txtCustomer.Text = "";
            }
        }
        private void SetFieldsByTraveApp(HrTravelApplicationEntity traveApp)
        {
            if (traveApp != null)
            {
                txtRelatedId.Tag = traveApp;
                txtRelatedId.Text = traveApp.TravelCode;
            }
            else
            {
                txtRelatedId.Tag = null;
                txtRelatedId.Text = "";
            }
        }
        private void BindComboBox()
        {
            UICommon.UICommonFunctions.BindComboboxByCommonItem(cmbStatus, "SFS", false);
            UICommon.UICommonFunctions.BindComboboxByCommonItem(cmbFeeType, "FEE", false);
            UICommon.UICommonFunctions.BindComboboxByCommonItemWithCode(cmbOrderType, "CFT", true);

            DataTable dt = new DataTable();
            dt.Columns.Add("ValueMember", typeof(string));
            dt.Columns.Add("DisplayMember", typeof(string));

            Array array = Enum.GetValues(typeof(PaymentType));
            foreach (Enum enumValue in array)
            {
                DataRow dr = dt.NewRow();
                dr["DisplayMember"] = enumValue.ToString();
                dr["ValueMember"] = Convert.ToInt32(enumValue).ToString();
                dt.Rows.Add(dr);
            }
            dt.AcceptChanges();
            treeFinPaymentType.DisplayMember = "DisplayMember";
            treeFinPaymentType.ValueMember = "ValueMember";
            treeFinPaymentType.DataSource = dt;
        }
        private void SetFields()
        {
            if (SelectedSalesFee == null)
            {
                return;
            }

            //Person
            if (string.IsNullOrEmpty(SelectedSalesFee.CustomerId) == false)
            {
                MstCustomerEntity customer = MstCustomerBs.GetMstCustomerByID(SelectedSalesFee.CustomerId);
                SetFieldsByCustomer(customer);
            }
            //HrTravelApplicationEntity
            if (string.IsNullOrEmpty(SelectedSalesFee.RelatedId) == false)
            {
                HrTravelApplicationEntity entity = HrTravelApplicationBs.GetById(SelectedSalesFee.RelatedId);
                SetFieldsByTraveApp(entity);
            }
            cmbFeeType.SetSelectedValue(SelectedSalesFee.FeeType);
            if (cmbFeeType.SelectedIndex == -1)
            {
                cmbFeeType.SelectedIndex = 0;
            }
            if (SelectedSalesFee.FeeStartDate.ToString("yyyy-MM-dd") == "1900-01-01" ||
                SelectedSalesFee.FeeStartDate.ToString("yyyy-MM-dd") == "0001-01-01")
            {
                dtpFeeStartDate.EditValue = null;
            }
            else
            {
                dtpFeeStartDate.EditValue = SelectedSalesFee.FeeStartDate;
            }
            if (SelectedSalesFee.FeeEndDate.ToString("yyyy-MM-dd") == "1900-01-01" ||
                SelectedSalesFee.FeeEndDate.ToString("yyyy-MM-dd") == "0001-01-01")
            {
                dtpFeeEndDate.EditValue = null;
            }
            else
            {
                dtpFeeEndDate.EditValue = SelectedSalesFee.FeeEndDate;
            }
            txtAttachedFile.Text = SelectedSalesFee.AttachedFile;
            txtOrderAmount.Text = SelectedSalesFee.OrderAmount.ToString("#0.00");
            MstPersonEntity person = null;
            if (ThisActionType == ActionType.New)
            {
                person = MstPersonBs.GetMstPersonByID(CommonParameter.CurrentUser.PersonId);
                if (person != null)
                {
                    txtPerson.Tag = person;
                    txtPerson.Text = person.NameCn + " (" + person.PersonCode + ")";
                }
            }
            else
            {
                if (string.IsNullOrEmpty(SelectedSalesFee.PersonId) == false)
                {
                    person = MstPersonBs.GetMstPersonByID(SelectedSalesFee.PersonId);
                    if (person != null)
                    {
                        txtPerson.Tag = person;
                        txtPerson.Text = person.NameCn + " (" + person.PersonCode + ")";
                    }
                }
            }
            txtSalesAmount.Text = SelectedSalesFee.SalesAmount.ToString("#0.00");
            txtAdvanceAmount.Text = "0";
            if (person != null)
            {
                txtAdvanceAmount.Text = person.AdvanceAmount.ToString("#0.00");
            }
            cmbStatus.SetSelectedValue(SelectedSalesFee.Status);
            txtRemark.Text = SelectedSalesFee.Remark;

            //Approve
            txtApprovedAmount.Text = SelectedSalesFee.ApprovedAmount.ToString("#0.00");
            txtApproveRemark.Text = SelectedSalesFee.ApproveRemark;

            //CEO Approve
            txtCeoApprovedAmount.Text = SelectedSalesFee.CeoApprovedAmount.ToString("#0.00");
            txtCeoApprovedRemark.Text = SelectedSalesFee.CeoApprovedRemark;
            txtUseAdvanceAmount.Text = SelectedSalesFee.UseAdvanceAmount.ToString("#0.00");
            txtCeoApprovedSalesFee.Text = SelectedSalesFee.CeoApprovedSalesFee.ToString("#0.00");
            txtExpenseAmount.Text = SelectedSalesFee.ExpenseAmount.ToString("#0.00");

            //Finance
            txtFinPaidAmount.Text = SelectedSalesFee.FinPaidAmount.ToString("#0.00");
            if (SelectedSalesFee.FinPaidDate.ToString("yyyy-MM-dd") == "1900-01-01" ||
                SelectedSalesFee.FinPaidDate.ToString("yyyy-MM-dd") == "0001-01-01")
            {
                dtpFinPaidDate.EditValue = null;
            }
            else
            {
                dtpFinPaidDate.EditValue = SelectedSalesFee.FinPaidDate;
            }
            if (string.IsNullOrEmpty(SelectedSalesFee.FinPaymentType) == false)
            {
                foreach (CheckedListBoxItem node in treeFinPaymentType.Items)
                {
                    if (SelectedSalesFee.FinPaymentType.IndexOf(node.Value.ToString()) >= 0)
                    {
                        node.CheckState = CheckState.Checked;
                    }
                }
            }
            cmbOrderType.SetSelectedValue(SelectedSalesFee.FinOrderType);

            UICommonFunctions.SetTextBoxDate(txtCreatedDate, SelectedSalesFee.CreatedDate, "yyyy-MM-dd hh:mm:ss");
            UICommonFunctions.SetTextBoxPersonName(txtCreatedBy, SelectedSalesFee.CreatedBy);
            UICommonFunctions.SetTextBoxDate(txtLastModifiedDate, SelectedSalesFee.LastModifiedDate, "yyyy-MM-dd hh:mm:ss");
            UICommonFunctions.SetTextBoxPersonName(txtLastModifiedBy, SelectedSalesFee.LastModifiedBy);
            UICommonFunctions.SetTextBoxDate(txtApprovedDate, SelectedSalesFee.ApprovedDate, "yyyy-MM-dd hh:mm:ss");
            UICommonFunctions.SetTextBoxPersonName(txtApprovedBy, SelectedSalesFee.ApprovedBy);
            UICommonFunctions.SetTextBoxDate(txtCeoApprovedDate, SelectedSalesFee.CeoApprovedDate, "yyyy-MM-dd hh:mm:ss");
            UICommonFunctions.SetTextBoxPersonName(txtCeoApprovedBy, SelectedSalesFee.CeoApprovedBy);
            UICommonFunctions.SetTextBoxPersonName(txtFinPaymentBy, SelectedSalesFee.FinPaymentBy);
        }
        private void SetEntity()
        {
            if (txtCustomer.Tag != null && txtCustomer.Tag.GetType() == typeof(MstCustomerEntity))
            {
                SelectedSalesFee.CustomerId = ((MstCustomerEntity)txtCustomer.Tag).CustomerId;
            }
            if (txtRelatedId.Tag != null && txtRelatedId.Tag.GetType() == typeof(HrTravelApplicationEntity))
            {
                SelectedSalesFee.RelatedId = ((HrTravelApplicationEntity)txtRelatedId.Tag).ApplicationId;
            }
            if (cmbFeeType.SelectedValue != null && cmbFeeType.SelectedValue.ToString().Trim() != "")
            {
                SelectedSalesFee.FeeType = CommonFunctions.ToString(cmbFeeType.SelectedValue);
            }
            if (dtpFeeStartDate.EditValue != null)
            {
                SelectedSalesFee.FeeStartDate = Convert.ToDateTime(dtpFeeStartDate.EditValue.ToString());
            }
            if (dtpFeeEndDate.EditValue != null)
            {
                SelectedSalesFee.FeeEndDate = Convert.ToDateTime(dtpFeeEndDate.EditValue.ToString());
            }
            SelectedSalesFee.AttachedFile = txtAttachedFile.Text;
            if (txtPerson.Tag != null && txtPerson.Tag.GetType() == typeof(MstPersonEntity))
            {
                SelectedSalesFee.PersonId = ((MstPersonEntity)txtPerson.Tag).PersonId;
            }
            if (string.IsNullOrEmpty(txtOrderAmount.Text) == false)
            {
                SelectedSalesFee.OrderAmount = CommonFunctions.ToDecimal(txtOrderAmount.Text);
            }
            if (string.IsNullOrEmpty(txtSalesAmount.Text) == false)
            {
                SelectedSalesFee.SalesAmount = CommonFunctions.ToDecimal(txtSalesAmount.Text);
            }
            SelectedSalesFee.Status = SalesFeeStatus.SFS01.ToString();
            SelectedSalesFee.Remark = txtRemark.Text;

            if (ThisActionType == ActionType.New)
            {
                SelectedSalesFee.CreatedDate = DateTime.Now;
                SelectedSalesFee.CreatedBy = CommonParameter.CurrentUser.PersonId;
            }
            if (ThisActionType == ActionType.New || ThisActionType == ActionType.Modify)
            {
                SelectedSalesFee.LastModifiedDate = DateTime.Now;
                SelectedSalesFee.LastModifiedBy = CommonParameter.CurrentUser.PersonId;
            }
            if (ThisActionType == ActionType.Approve)
            {
                switch (ThisApproveType)
                {
                    case ApproveType.DM:
                        SelectedSalesFee.ApprovedAmount = CommonFunctions.ToDecimal(txtApprovedAmount.Text);
                        SelectedSalesFee.ApprovedDate = DateTime.Now;
                        SelectedSalesFee.ApprovedBy = CommonParameter.CurrentUser.PersonId;
                        SelectedSalesFee.ApproveRemark = txtApproveRemark.Text;
                        break;
                    case ApproveType.CEO:
                        SelectedSalesFee.CeoApprovedAmount = CommonFunctions.ToDecimal(txtCeoApprovedAmount.Text);
                        SelectedSalesFee.CeoApprovedDate = DateTime.Now;
                        SelectedSalesFee.CeoApprovedBy = CommonParameter.CurrentUser.PersonId;
                        SelectedSalesFee.CeoApprovedRemark = txtCeoApprovedRemark.Text;
                        SelectedSalesFee.UseAdvanceAmount = CommonFunctions.ToDecimal(txtUseAdvanceAmount.Text);
                        SelectedSalesFee.CeoApprovedSalesFee = CommonFunctions.ToDecimal(txtCeoApprovedSalesFee.Text);
                        SelectedSalesFee.ExpenseAmount = CommonFunctions.ToDecimal(txtExpenseAmount.Text);
                        break;
                    case ApproveType.FIN:
                        SelectedSalesFee.FinPaidDate = DateTime.Now;
                        SelectedSalesFee.FinPaymentBy = CommonParameter.CurrentUser.PersonId;
                        SelectedSalesFee.FinPaidAmount = CommonFunctions.ToDecimal(txtFinPaidAmount.Text);
                        SelectedSalesFee.FinPaymentType = "";
                        if (string.IsNullOrEmpty(SelectedSalesFee.FinPaymentType) == false)
                        {
                            foreach (CheckedListBoxItem node in treeFinPaymentType.Items)
                            {
                                if (SelectedSalesFee.FinPaymentType.IndexOf(node.Value.ToString()) >= 0)
                                {
                                    node.CheckState = CheckState.Checked;
                                }
                            }
                        }
                        if (cmbOrderType.SelectedValue != null)
                        {
                            SelectedSalesFee.FinOrderType = cmbOrderType.SelectedValue.ToString();
                        }
                        break;
                }
            }
        }
        private bool CheckData()
        {
            if (string.IsNullOrEmpty(txtPerson.Text))
            {
                MessageBox.Show("报销人不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
            if (cmbFeeType.SelectedValue == null || string.IsNullOrEmpty(cmbFeeType.SelectedValue.ToString()))
            {
                MessageBox.Show("费用类型不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
            if (dtpFeeStartDate.EditValue == null)
            {
                MessageBox.Show("起始日期不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
            if (dtpFeeEndDate.EditValue == null)
            {
                MessageBox.Show("结束日期不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
            if (string.IsNullOrEmpty(txtOrderAmount.Text))
            {
                MessageBox.Show("本单金额不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
            if (string.IsNullOrEmpty(txtSalesAmount.Text))
            {
                MessageBox.Show("销售费用不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
            if (ThisActionType == ActionType.Approve)
            {
                switch (ThisApproveType)
                {
                    case ApproveType.DM:
                        if (CommonFunctions.ToDecimal(txtApprovedAmount.Text) <= 0)
                        {
                            MessageBox.Show("审核金额不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return false;
                        }
                        break;
                    case ApproveType.CEO:
                        if (CommonFunctions.ToDecimal(txtCeoApprovedAmount.Text) <= 0)
                        {
                            MessageBox.Show("审批金额不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return false;
                        }
                        //if (CommonFunctions.ToDecimal(txtCeoApprovedSalesFee.Text) <= 0)
                        //{
                        //    MessageBox.Show("销售费用金额不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        //    return false;
                        //}
                        break;
                    case ApproveType.FIN:
                        if (dtpFinPaidDate.EditValue == null)
                        {
                            MessageBox.Show("支付日期不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return false;
                        }
                        if (CommonFunctions.ToDecimal(txtFinPaidAmount.Text) <= 0)
                        {
                            MessageBox.Show("实付金额不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return false;
                        }
                        bool paymentType = false;
                        foreach (CheckedListBoxItem node in treeFinPaymentType.Items)
                        {
                            if (node.CheckState == CheckState.Checked)
                            {
                                paymentType = true;
                            }
                        }
                        if (paymentType == false)
                        {
                            MessageBox.Show("支付类型不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return false;
                        }
                        if (cmbOrderType.SelectedValue == null || string.IsNullOrEmpty(cmbOrderType.SelectedValue.ToString()))
                        {
                            MessageBox.Show("核算项目不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return false;
                        }
                        break;
                }
            }
            return true;
        }
        private bool Save()
        {
            try
            {
                if (CheckData() == false)
                {
                    return false;
                }
                if (ThisActionType == ActionType.New)
                {
                    SetEntity();
                    bool isSuccessful = SalesFeeBs.InsertSalesFee(SelectedSalesFee);
                    if (!isSuccessful)
                    {
                        MessageBox.Show("新增失败！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return false;
                    }
                }
                else if (ThisActionType == ActionType.Modify)
                {
                    SetEntity();
                    bool isSuccessful = SalesFeeBs.UpdateSalesFee(SelectedSalesFee);
                    if (!isSuccessful)
                    {
                        MessageBox.Show("修改失败！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return false;
                    }
                }
                else if (ThisActionType == ActionType.Approve && ThisApproveType != ApproveType.FIN)//审核,审批
                {
                    bool isSuccessful = SalesFeeBs.ApproveSalesFee(SelectedSalesFee);
                    if (!isSuccessful)
                    {
                        MessageBox.Show("审核失败！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return false;
                    }
                }
                else if (ThisActionType == ActionType.Approve && ThisApproveType == ApproveType.FIN)//财务报销
                {
                    if (Convert.ToDecimal(txtFinPaidAmount.Text) != Convert.ToDecimal(txtSalesAmount.Text))
                    {
                        DialogResult dr = MessageBox.Show("财务报销金额不等于报销申请金额，确认继续吗？","Information",MessageBoxButtons.YesNo,MessageBoxIcon.Question);
                        if (dr == DialogResult.No)
                        {
                            return false;
                        }
                    }
                    SelectedSalesFee.Status = SalesFeeStatus.SFS06.ToString();
                    bool isSuccessful = SalesFeeBs.ApproveSalesFee(SelectedSalesFee);
                    if (!isSuccessful)
                    {
                        MessageBox.Show("报销失败！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return false;
                    }
                }
                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
        }
        private void ResetExpenseAmount()
        {
            decimal ceoApproveAmount = CommonFunctions.ToDecimal(txtCeoApprovedAmount.Text);
            decimal useAdvanceAmount = CommonFunctions.ToDecimal(txtUseAdvanceAmount.Text);
            decimal expenseAmount = ceoApproveAmount - useAdvanceAmount;
            txtExpenseAmount.Text = expenseAmount.ToString("#0.00");
        }
        #endregion

        #region Event
        protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);
            BindComboBox();
            SetFields();
            if (txtCustomer.Tag != null && txtCustomer.Tag.GetType() == typeof(MstCustomerEntity))
            {
                SetFieldsByCustomer((MstCustomerEntity)txtCustomer.Tag);
            }
            if (ThisActionType == ActionType.New)
            {
                MstPersonEntity person = MstPersonBs.GetMstPersonByID(CommonParameter.CurrentUser.PersonId);
                if (person != null)
                {
                    txtPerson.Tag = person;
                    txtPerson.Text = person.NameCn;
                }
            }
        }
        protected override void Click_Save()
        {
            if (Save())
            {
                this.DialogResult = DialogResult.OK;
            }
        }
        protected override void Click_SaveNew()
        {
            if (Save())
            {
                ThisActionType = ActionType.New;
                SelectedSalesFee = new SalesFeeEntity();
                SelectedSalesFee.SalesFeeId = Guid.NewGuid().ToString();
                SetFields();
            }
        }
        protected override void Click_Approve()
        {
            if (SelectedSalesFee == null)
            {
                return;
            }
            SetEntity();
            if (ThisApproveType == ApproveType.DM)//审核
            {
                SelectedSalesFee.Status = SalesFeeStatus.SFS02.ToString();
            }
            else if (ThisApproveType == ApproveType.CEO)//审批
            {
                SelectedSalesFee.Status = SalesFeeStatus.SFS04.ToString();
            }
            if (Save())
            {
                this.DialogResult = DialogResult.OK;
            }
        }
        protected override void Click_Reject()
        {
            if (SelectedSalesFee == null)
            {
                return;
            }
            SetEntity();
            if (ThisApproveType == ApproveType.DM)//审核拒绝
            {
                SelectedSalesFee.Status = SalesFeeStatus.SFS03.ToString();
            }
            else if (ThisApproveType == ApproveType.CEO)//审批拒绝
            {
                SelectedSalesFee.Status = SalesFeeStatus.SFS05.ToString();
            }
            if (Save())
            {
                this.DialogResult = DialogResult.OK;
            }
        }

        private void txtPerson_ButtonClick(object sender, ButtonPressedEventArgs e)
        {
            frmMaintainEmployeeQuery frm = new frmMaintainEmployeeQuery();
            if (frm.ShowDialog() == DialogResult.OK && frm.SelectedPerson != null)
            {
                txtPerson.Text = frm.SelectedPerson.NameCn;
                txtPerson.Tag = frm.SelectedPerson;
                txtAdvanceAmount.Text = "0";
                if (frm.SelectedPerson != null)
                {
                    txtAdvanceAmount.Text = frm.SelectedPerson.AdvanceAmount.ToString("#0.00");
                }
            }
            else
            {
                txtPerson.Text = "";
                txtPerson.Tag = null;
            }
        }

        private void txtCustomer_ButtonClick(object sender, ButtonPressedEventArgs e)
        {
            if (txtPerson.Tag == null || txtPerson.Tag.GetType() != typeof(MstPersonEntity))
            {
                MessageBox.Show("请先选择业务员！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            frmMaintainCustomerQuery frm = new frmMaintainCustomerQuery((MstPersonEntity)txtPerson.Tag);
            if (frm.ShowDialog() == DialogResult.OK && frm.SelectedCustomer != null)
            {
                SetFieldsByCustomer(frm.SelectedCustomer);
            }
            else
            {
                SetFieldsByCustomer(null);
            }
        }

        private void txtAttachedFile_ButtonClick(object sender, ButtonPressedEventArgs e)
        {

        }

        private void txtRelatedId_ButtonClick(object sender, ButtonPressedEventArgs e)
        {
            frmMaintainTravelApplicationQuery frm = new frmMaintainTravelApplicationQuery();
            if (frm.ShowDialog() == DialogResult.OK && frm.SelectedTravelApp != null)
            {
                SetFieldsByTraveApp(frm.SelectedTravelApp);
            }
            else
            {
                SetFieldsByTraveApp(null);
            }
        }

        private void txtUseAdvanceAmount_EditValueChanged(object sender, EventArgs e)
        {
            ResetExpenseAmount();
        }

        private void txtApprovedAmount_EditValueChanged(object sender, EventArgs e)
        {
            if (txtSalesAmount.EditValue != null &&
                txtApprovedAmount.EditValue != null)
            {
                if (Convert.ToDecimal(txtApprovedAmount.Text) > Convert.ToDecimal(txtSalesAmount.Text))
                {
                    MessageBox.Show("审核金额不能大于报销申请金额！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtApprovedAmount.EditValue = null;
                    txtApprovedAmount.Refresh();
                    return;
                }
            }
        }

        private void txtCeoApprovedAmount_EditValueChanged(object sender, EventArgs e)
        {
            if (txtSalesAmount.EditValue != null &&
                txtApprovedAmount.EditValue != null &&
                txtCeoApprovedAmount != null)
            {
                if (Convert.ToDecimal(txtCeoApprovedAmount.Text) > Convert.ToDecimal(txtSalesAmount.Text))
                {
                    MessageBox.Show("审批金额不能大于报销申请金额！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtCeoApprovedAmount.EditValue = null;
                    txtCeoApprovedAmount.Refresh();
                    return;
                }
            }
            ResetExpenseAmount();
        }

        private void txtFinPaidAmount_EditValueChanged(object sender, EventArgs e)
        {
            //txtFinPaidAmount

            if (txtSalesAmount.EditValue != null &&
                txtApprovedAmount.EditValue != null &&
                txtCeoApprovedAmount != null &&
                txtFinPaidAmount != null)
            {
                if (Convert.ToDecimal(txtFinPaidAmount.Text) > Convert.ToDecimal(txtSalesAmount.Text))
                {
                    MessageBox.Show("财务报销金额不能大于报销金额！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtFinPaidAmount.EditValue = null;
                    txtFinPaidAmount.Refresh();
                    return;
                }
            }
        }
        #endregion
    }
}
